package com.qfedu.knowledge.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qfedu.knowledge.dao.QuestionMasterDao;
import com.qfedu.knowledge.entity.bo.QuestionMasterBO;
import com.qfedu.knowledge.service.IQuestionMasterService;
import com.qfedu.knowledge.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName QuestionMasterServiceImpl
 * @Author ykx
 * @Date 2024/4/28 11:09
 * @Version 1.0
 */
@Service
public class QuestionMasterServiceImpl extends ServiceImpl<QuestionMasterDao, QuestionMasterBO>
        implements IQuestionMasterService {

    @Autowired
    private QuestionMasterDao questionMasterDao;


    @Autowired
    private SecurityUtils securityUtils;

    @Override
    public Boolean master(List<Long> ids) {
        List<QuestionMasterBO> list = new ArrayList<>();
        Long userId = securityUtils.getCurrentUser().getId();
        for (Long id : ids) {
            QuestionMasterBO questionMasterBO = new QuestionMasterBO();
            questionMasterBO.setQuestionId(id);
            questionMasterBO.setUserId(userId);
            list.add(questionMasterBO);
        }

        return saveBatch(list);
    }

    @Override
    public Boolean master(Long id) {
        QuestionMasterBO questionMasterBO = new QuestionMasterBO();
        questionMasterBO.setUserId(securityUtils.getCurrentUser().getId());
        questionMasterBO.setQuestionId(id);
        return save(questionMasterBO);
    }

    @Override
    public Boolean deleteById(Long masterId) {
        return questionMasterDao.removeById(masterId);
    }
}
